package com.ev.framework.utils;

import cn.afterturn.easypoi.entity.vo.TemplateExcelConstants;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.view.PoiBaseView;
import com.google.common.collect.Maps;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
 * 生成excel 报表
 */
public class EasyPoiUtils {
    public static void processingExport(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, String fileName, List<?> dateList, String chineseName) {
        ClassPathResource classPathResource = new ClassPathResource(fileName);
        Map<String, Object> map = Maps.newHashMap();
        map.put("list", dateList);
        TemplateExportParams result = new TemplateExportParams(classPathResource.getPath());
        modelMap.put(TemplateExcelConstants.FILE_NAME, chineseName);
        modelMap.put(TemplateExcelConstants.PARAMS, result);
        modelMap.put(TemplateExcelConstants.MAP_DATA, map);
        PoiBaseView.render(modelMap, request, response,
                TemplateExcelConstants.EASYPOI_TEMPLATE_EXCEL_VIEW);
    }
}
